package com.xjtu.platform.demander.editquestion.impl;

import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.common.Utils;
import com.xjtu.platform.demander.editquestion.EditquestionDto;
import com.xjtu.platform.demander.editquestion.EditquestionService;
import com.xjtu.platform.demander.editquestion.OptionsDto;
import com.xjtu.platform.demander.editquestion.dao.EditquestionDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import java.util.Map;
import java.util.UUID;

@Service
@Transactional
public class EditquestionImpl implements EditquestionService {
    @Resource
    private EditquestionDao editquestionDao;


    @Override
    public Map<String, Object> getEditquestionList( CurrentUser currentUser ) {
        return Utils.getPage(currentUser ,()->editquestionDao.findEditquestionList(currentUser ));
    }

    @Override
    public void updateQuestion(EditquestionDto dto) {
        editquestionDao.updatequestion(dto);
    }

    @Override
    public boolean insertOption(OptionsDto optionsDto) {
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        System.out.println(id);
        String oid = id.toString();
        try {
            editquestionDao.insertOpt(optionsDto,oid);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public void deleteoption(OptionsDto optionsDto) {
        editquestionDao.deleteoption(optionsDto);
    }

    @Override
    public void addStage(String request_id) {
        editquestionDao.addStage(request_id);
    }

}
